package sdc.com.petscalendar.fragments;

import sdc.com.petscalendar.R;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class CalendarMonthFragment extends BaseFragment implements
		View.OnClickListener {
	TextView[] mBtnMonthArray = new TextView[12];

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		if (mView == null) {
			mView = inflater.inflate(R.layout.fragment_calendar_month,
					container, false);
		}
		return mView;
	}

	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		super.onViewCreated(view, savedInstanceState);
		mBtnMonthArray[0] = (TextView) getView().findViewById(R.id.tv_month1);
		mBtnMonthArray[1] = (TextView) getView().findViewById(R.id.tv_month2);
		mBtnMonthArray[2] = (TextView) getView().findViewById(R.id.tv_month3);
		mBtnMonthArray[3] = (TextView) getView().findViewById(R.id.tv_month4);
		mBtnMonthArray[4] = (TextView) getView().findViewById(R.id.tv_month5);
		mBtnMonthArray[5] = (TextView) getView().findViewById(R.id.tv_month6);
		mBtnMonthArray[6] = (TextView) getView().findViewById(R.id.tv_month7);
		mBtnMonthArray[7] = (TextView) getView().findViewById(R.id.tv_month8);
		mBtnMonthArray[8] = (TextView) getView().findViewById(R.id.tv_month9);
		mBtnMonthArray[9] = (TextView) getView().findViewById(R.id.tv_month10);
		mBtnMonthArray[10] = (TextView) getView().findViewById(R.id.tv_month11);
		mBtnMonthArray[11] = (TextView) getView().findViewById(R.id.tv_month12);

		for (int i = 0; i < mBtnMonthArray.length; i++) {
			mBtnMonthArray[i].setOnClickListener(this);
		}
	}

	@Override
	public void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
	}

	@Override
	public void onClick(View v) {
		for (int i = 0; i < mBtnMonthArray.length; i++) {
			if (v.getId() == mBtnMonthArray[i].getId()) {
				FragmentTransaction fragmentTransaction = getFragmentManager()
						.beginTransaction();
				CalendarDayFragment fragment = new CalendarDayFragment();
				Bundle data = new Bundle();
				data.putInt("month", i);
				fragment.setArguments(data);
				fragmentTransaction.replace(R.id.frm_calendar, fragment);
				fragmentTransaction.addToBackStack(null);
				fragmentTransaction.commit();
				return;
			}
		}

	}
}
